<template>
	<view style="background-color: whitesmoke;">
		<xweek v-on:back="changeBack" @filterType="handleFilterType"></xweek> 
		<view class="action" style="display: flex; align-items: center;">
		  <text class="text-grey text-sm" style="margin: 10px;">今日任务</text>
		</view>
		<!-- 重要 -->
		<view >
			<view 
			style="border: 5px;background-color: white;margin-top: 5px;margin-bottom: 5px;">
				<view class="item-title margin-bottom-sm margin-top-sm " id="taskLevel"
				style="border: 10px;background-color: white;margin: 5px;font-size: 10px;color: goldenrod;padding-top: 10px;" v-if="taskList.mostHight != null">
					<text class="cuIcon-info" style="border-left: 10px; margin-left: 7px;color: red;"> 最高</text>
				</view>
				<l-swipeAction :options="options" @clickItem="clickItem(c)" v-for="c in taskList.mostHight">
					<view class="" style="width: 100%;background-color: white;margin-left: 10px;">
						<view  class="container" @click="getTaskDetail(c)">
							<!-- <checkbox :class="c.states?'checked':''" value="c.states" :checked="c.states"  color="#FFCC33" style="transform:scale(0.7);  margin-left: 7px;" /> -->
							
							<text :class="{ 'strikethrough': c.states } "  :key="c.id"
							style="border: 10px;background-color: white;margin-top: 5px;font-size: 12px;padding: 10px;" >
								{{c.taskName}}
							</text>
							
							<text v-if="c.states"  color="#FFCC33" style="color: green;font-size:10px;" >已完成：{{c.finishTime}}</text>
							<text v-if="!c.states && c.sureState"  color="#FFCC33" style="color: red;font-size:10px;">进行中</text>
							<view class="" v-if="c.staffId == staff.id && !c.sureState">
								<button color="#FFCC33" style="color: black;margin-left: 10px;font-size:10px;background-color: skyblue;"  @tap.stop="sureTask(c)">请确认收到任务</button>
							</view>
							<view class="" v-if="c.creatStaffId == staff.id && !c.sureState">
								<view  color="#FFCC33" style="color: red;font-size:10px;" v-if="c.creatStaffId == staff.id">任务待接收</view>
							</view>
							<text style="margin-right: 15px; background-color: red; color: white;margin-left: auto;padding: 3px;font-size:9px"
							v-if="calculateDifference(c.endTime, nowDate) > 0 && !c.states">
								延期{{ calculateDifference(c.endTime, nowDate) }}天
							</text>
					
						</view>
							<view v-if="c.projectDetails" style="padding-left: 40px;" class="cuIcon-rank">
							<text style="padding-left: 10px;font-size: 11px;">{{c.projectDetails}}</text></view>
					</view>
				</l-swipeAction>
			</view>
		</view>
		
		<!-- 较高 -->
		<view >
			<view 
			style="border: 5px;background-color: white;margin-top: 5px;margin-bottom: 5px;">
				<view class="item-title margin-bottom-sm margin-top-sm " id="taskLevel"
				style="border: 10px;background-color: white;margin: 5px;font-size: 10px;color: goldenrod;padding-top: 10px;" v-if="taskList.Hight != null">
					<text class="cuIcon-info" style="border-left: 10px; margin-left: 7px;"> 较高</text>
				</view>
				<l-swipeAction :options="options" @clickItem="clickItem(c)" v-for="c in taskList.Hight">
				  <view class="" style="width: 100%;height: 50px;background-color: white;">
						<view class="container" @click="getTaskDetail(c)">
								<!-- <checkbox :class="c.states?'checked':''" value="c.states" :checked="c.states" color="#FFCC33" style="transform:scale(0.7);  margin-left: 7px;" /> -->
								<text :class="{ 'strikethrough': c.states } "  :key="c.id"
								style="border: 10px;background-color: white;margin-top: 5px;font-size: 12px;padding: 10px;" >
									{{c.taskName}}
								</text>
								
								<text v-if="c.states"  color="#FFCC33" style="color: green;font-size:10px;" >已完成：{{c.finishTime}}</text>
								<text v-if="!c.states && c.sureState"  color="#FFCC33" style="color: red;font-size:10px;" >进行中</text>
								<!-- <text v-if="c.staffId == staff.id && c.sureState == 0"  color="#FFCC33" style="color: black;margin-left: 10px;" @tap.stop="sureTask(c)">请确认收到任务</text> -->
								<view class="" v-if="c.staffId == staff.id && !c.sureState">
									<button color="#FFCC33" style="color: black;margin-left: 10px;font-size:10px;background-color: skyblue;" @tap.stop="sureTask(c)">请确认收到任务</button>
								</view>
								<text style="margin-right: 15px; background-color: red; color: white;margin-left: auto;padding: 3px;font-size:9px"
								v-if="calculateDifference(c.endTime, nowDate) > 0 && !c.states">
									延期{{ calculateDifference(c.endTime, nowDate) }}天
								</text>
						</view>
					</view>
				</l-swipeAction>
			</view>
		</view>
		<!-- 一般 -->
		<view >
			<view 
			style="border: 5px;background-color: white;margin-top: 5px;margin-bottom: 5px;">
				<view class="item-title margin-bottom-sm margin-top-sm " id="taskLevel"
				style="border: 10px;background-color: white;margin: 5px;font-size: 10px;color: goldenrod;padding-top: 10px;" v-if="taskList.common != null">
					<text class="cuIcon-info" style="border-left: 10px; margin-left: 7px;color: purple;"> 一般</text>
				</view>
				<l-swipeAction :options="options" @clickItem="clickItem(c)" v-for="c in taskList.common">
				  <view class="" style="width: 100%;height: 50px;background-color: white;">
						<view class="container" @click="getTaskDetail(c)">
							<!-- <checkbox :class="c.states?'checked':''" value="c.states" :checked="c.states" color="#FFCC33" style="transform:scale(0.7);  margin-left: 7px;" /> -->
							<text :class="{ 'strikethrough': c.states } " :key="c.id"
							style="border: 10px;background-color: white;margin-top: 5px;font-size: 12px;padding: 10px;" >
								{{c.taskName}}
							</text>
							
							<text v-if="c.states"  color="#FFCC33" style="color: green;font-size:10px;" >已完成：{{c.finishTime}}</text>
							<text v-if="!c.states && c.sureState"  color="#FFCC33" style="color: red;font-size:10px;" >进行中</text>
							<view class="" v-if="c.staffId == staff.id && !c.sureState">
								<button color="#FFCC33" style="color: black;margin-left: 10px;font-size:10px;background-color: skyblue;" @tap.stop="sureTask(c)">请确认收到任务</button>
							</view>
							<text style="margin-right: 15px; background-color: red; color: white;margin-left: auto;padding: 3px;font-size:9px"
							v-if="calculateDifference(c.endTime, nowDate) > 0 && !c.states">
								延期{{ calculateDifference(c.endTime, nowDate) }}天
							</text>
						</view>
					</view>
				</l-swipeAction>
			</view>
		</view>
		
		<!-- 不重要 -->
		<view >
			<view 
			style="border: 5px;background-color: white;margin-top: 5px;margin-bottom: 5px;">
				<view class="item-title margin-bottom-sm margin-top-sm " id="taskLevel"
				style="border: 10px;background-color: white;margin: 5px;font-size: 10px;color: goldenrod;padding-top: 10px;" v-if="taskList.low != null">
					<text class="cuIcon-info" style="border-left: 10px; margin-left: 7px;color: green;"> 较低</text>
				</view>
				<l-swipeAction :options="options" @clickItem="clickItem(c)" v-for="c in taskList.low">
				  <view class="" style="width: 100%;height: 50px;background-color: white;">
						<view class="container" @click="getTaskDetail(c)" >
							<!-- <checkbox :class="c.states?'checked':''" value="c.states" :checked="c.states" color="#FFCC33" style="transform:scale(0.7);  margin-left: 7px;"/> -->
							<text :class="{ 'strikethrough': c.states } " :key="c.id"
							style="border: 10px;background-color: white;margin-top: 5px;font-size: 12px;padding: 10px;" >
								{{c.taskName}}
							</text>
							<!-- <text style="margin-right: 15px; background-color: red; color: white;margin-left: auto;padding: 3px;font-size:9px"
							v-if="calculateDifference(c.endTime, nowDate) > 0 && c.taskProgress != 100">
								延期{{ calculateDifference(c.endTime, nowDate) }}天
							</text> -->
							
							<text v-if="c.states"  color="#FFCC33" style="color: green;font-size:10px;" >已完成：{{c.finishTime}}</text>
							<text v-if="!c.states && c.sureState"  color="#FFCC33" style="color: red;font-size:10px;" >进行中</text>
							<view class="" v-if="c.staffId == staff.id && !c.sureState">
								<button color="#FFCC33" style="color: black;margin-left: 10px;font-size:10px;background-color: skyblue;" @tap.stop="sureTask(c)">请确认收到任务</button>
							</view>
							<text style="margin-right: 15px; background-color: red; color: white;margin-left: auto;padding: 3px;font-size:9px"
							v-if="calculateDifference(c.endTime, nowDate) > 0 && !c.states">
								延期{{ calculateDifference(c.endTime, nowDate) }}天
							</text>
							
						</view>
					</view>
				</l-swipeAction>
			</view>
		</view>
		<view class="action" style="display: flex; align-items: center;">
		  <text class="text-grey text-sm" style="margin: 5px;">延期任务</text>
		</view>
		
		<!-- 重要 -->
		<view >
			<view 
			style="border: 5px;background-color: white;margin-top: 5px;margin-bottom: 5px;">
				<view class="item-title margin-bottom-sm margin-top-sm " id="taskLevel"
				style="border: 10px;background-color: white;margin: 5px;font-size: 10px;color: goldenrod;padding-top: 10px;" v-if="delayTask.mostHight != null">
					<text class="cuIcon-info" style="border-left: 10px; margin-left: 7px;color: red;"> 最高</text>
				</view>
				<l-swipeAction :options="options" @clickItem="clickItem(c)" v-for="c in delayTask.mostHight">
					<view class="" style="width: 100%;background-color: white;margin-left: 10px;">
						<view  class="container" @click="getTaskDetail(c)">
							<!-- <checkbox :class="c.states?'checked':''" value="c.states" :checked="c.states"  color="#FFCC33" style="transform:scale(0.7);  margin-left: 7px;" /> -->
							
							<text :class="{ 'strikethrough': c.states } "  :key="c.id"
							style="border: 10px;background-color: white;margin-top: 5px;font-size: 12px;padding: 10px;" >
								{{c.taskName}}
							</text>
							
							<text v-if="c.states"  color="#FFCC33" style="color: green;font-size:10px;" >已完成：{{c.finishTime}}</text>
							<text v-if="!c.states && c.sureState"  color="#FFCC33" style="color: red;font-size:10px;">进行中</text>
							<view class="" v-if="c.staffId == staff.id && !c.sureState">
								<button color="#FFCC33" style="color: black;margin-left: 10px;font-size:10px;background-color: skyblue;"  @tap.stop="sureTask(c)">请确认收到任务</button>
							</view>
							<view class="" v-if="c.creatStaffId == staff.id && !c.sureState">
								<view  color="#FFCC33" style="color: red;font-size:10px;" v-if="c.creatStaffId == staff.id">任务待接收</view>
							</view>
							<text style="margin-right: 15px; background-color: red; color: white;margin-left: auto;padding: 3px;font-size:9px"
							v-if="calculateDifference(c.endTime, nowDate) > 0 && !c.states">
								延期{{ calculateDifference(c.endTime, nowDate) }}天
							</text>
					
						</view>
							<view v-if="c.projectDetails" style="padding-left: 40px;" class="cuIcon-rank">
							<text style="padding-left: 10px;font-size: 11px;">{{c.projectDetails}}</text></view>
					</view>
				</l-swipeAction>
			</view>
		</view>
		
		<view >
			<view 
			style="border: 5px;background-color: white;margin-top: 5px;margin-bottom: 5px;">
				<view class="item-title margin-bottom-sm margin-top-sm " id="taskLevel"
				style="border: 10px;background-color: white;margin: 5px;font-size: 10px;color: goldenrod;padding-top: 10px;" v-if="delayTask.Hight != null">
					<text class="cuIcon-info" style="border-left: 10px; margin-left: 7px;"> 较高</text>
				</view>
				<l-swipeAction :options="options" @clickItem="clickItem(c)" v-for="c in delayTask.Hight">
				  <view class="" style="width: 100%;height: 50px;background-color: white;">
						<view class="container" @click="getTaskDetail(c)">
								<text :class="{ 'strikethrough': c.states } "  :key="c.id"
								style="border: 10px;background-color: white;margin-top: 5px;font-size: 12px;padding: 10px;" >
									{{c.taskName}}
								</text>
								
								<text v-if="c.states"  color="#FFCC33" style="color: green;font-size:10px;" >已完成：{{c.finishTime}}</text>
								<text v-if="!c.states && c.sureState"  color="#FFCC33" style="color: red;font-size:10px;" >进行中</text>
								<view class="" v-if="c.staffId == staff.id && !c.sureState">
									<button color="#FFCC33" style="color: black;margin-left: 10px;font-size:10px;background-color: skyblue;" @tap.stop="sureTask(c)">请确认收到任务</button>
								</view>
								<text style="margin-right: 15px; background-color: red; color: white;margin-left: auto;padding: 3px;font-size:9px"
								v-if="calculateDifference(c.endTime, nowDate) > 0 && !c.states">
									延期{{ calculateDifference(c.endTime, nowDate) }}天
								</text>
						</view>
					</view>
				</l-swipeAction>
			</view>
		</view>
		
		<view >
			<view 
			style="border: 5px;background-color: white;margin-top: 5px;margin-bottom: 5px;">
				<view class="item-title margin-bottom-sm margin-top-sm " id="taskLevel"
				style="border: 10px;background-color: white;margin: 5px;font-size: 10px;color: goldenrod;padding-top: 10px;" v-if="delayTask.common != null">
					<text class="cuIcon-info" style="border-left: 10px; margin-left: 7px;color: purple;"> 一般</text>
				</view>
				<l-swipeAction :options="options" @clickItem="clickItem(c)" v-for="c in delayTask.common">
				  <view class="" style="width: 100%;height: 50px;background-color: white;">
						<view class="container" @click="getTaskDetail(c)">
							<text :class="{ 'strikethrough': c.states } " :key="c.id"
							style="border: 10px;background-color: white;margin-top: 5px;font-size: 12px;padding: 10px;" >
								{{c.taskName}}
							</text>
							
							<text v-if="c.states"  color="#FFCC33" style="color: green;font-size:10px;" >已完成：{{c.finishTime}}</text>
							<text v-if="!c.states && c.sureState"  color="#FFCC33" style="color: red;font-size:10px;" >进行中</text>
							<view class="" v-if="c.staffId == staff.id && !c.sureState">
								<button color="#FFCC33" style="color: black;margin-left: 10px;font-size:10px;background-color: skyblue;" @tap.stop="sureTask(c)">请确认收到任务</button>
							</view>
							<text style="margin-right: 15px; background-color: red; color: white;margin-left: auto;padding: 3px;font-size:9px"
							v-if="calculateDifference(c.endTime, nowDate) > 0 && !c.states">
								延期{{ calculateDifference(c.endTime, nowDate) }}天
							</text>
						</view>
					</view>
				</l-swipeAction>
			</view>
		</view>
		
		<view >
			<view 
			style="border: 5px;background-color: white;margin-top: 5px;margin-bottom: 5px;">
				<view class="item-title margin-bottom-sm margin-top-sm " id="taskLevel"
				style="border: 10px;background-color: white;margin: 5px;font-size: 10px;color: goldenrod;padding-top: 10px;" v-if="delayTask.low != null">
					<text class="cuIcon-info" style="border-left: 10px; margin-left: 7px;color: green;"> 较低</text>
				</view>
				<l-swipeAction :options="options" @clickItem="clickItem(c)" v-for="c in delayTask.low">
				  <view class="" style="width: 100%;height: 50px;background-color: white;">
						<view class="container" @click="getTaskDetail(c)" >
							<text :class="{ 'strikethrough': c.states } " :key="c.id"
							style="border: 10px;background-color: white;margin-top: 5px;font-size: 12px;padding: 10px;" >
								{{c.taskName}}
							</text>
							
							<text v-if="c.states"  color="#FFCC33" style="color: green;font-size:10px;" >已完成：{{c.finishTime}}</text>
							<text v-if="!c.states && c.sureState"  color="#FFCC33" style="color: red;font-size:10px;" >进行中</text>
							<view class="" v-if="c.staffId == staff.id && !c.sureState">
								<button color="#FFCC33" style="color: black;margin-left: 10px;font-size:10px;background-color: skyblue;" @tap.stop="sureTask(c)">请确认收到任务</button>
							</view>
							<text style="margin-right: 15px; background-color: red; color: white;margin-left: auto;padding: 3px;font-size:9px"
							v-if="calculateDifference(c.endTime, nowDate) > 0 && !c.states">
								延期{{ calculateDifference(c.endTime, nowDate) }}天
							</text>
							
						</view>
					</view>
				</l-swipeAction>
			</view>
		</view>
		
		
		
		<!-- 添加评论 -->
		<modal v-if="areaShow" title="评论" confirm-text="保存" cancel-text="取消" @cancel="cancelAdd" @confirm="confirmAdd">
			<!-- <input type="text" v-model="areaTxt" placeholder="限填100个字" class="intxt" maxlength="100" /> -->
			<view class="cu-form-group margin-top">
				<textarea maxlength="-1" :disabled="modalName!=null" @input="textareaAInput" placeholder="多行文本输入框"  v-model="areaTxt"></textarea>
			</view> 
		</modal>
		<!-- 修改任务进度 -->
		<modal v-if="updateShow" title="修改任务进度" confirm-text="提交" cancel-text="取消" @cancel="cancelAdd" @confirm="updateProcess" >
			<view class="cu-form-group margin-top" name="progress">
				<input v-model="areaTxt" placeholder="请输入完成进度(数字1-100)" class="intxt" maxlength="100" v-text="number"  />
			</view>
		</modal>
		<view>
			<!-- 悬浮框  方法 :content="content"-->
			<uni-fab class="uni-combox__input" 
				:pattern="pattern"
				:horizontal="horizontal"
				:vertical="vertical"
				:direction="direction"
				@trigger="trigger"
				@fabClick="fabClick"
			></uni-fab>
		</view> 
		<text style="padding: 35px;"></text>
	</view>
	
</template>

<script>
	import request from '../../common/request';
	import common from 'common/common.js';
	import xweek from 'components/junkj-xweek/xweek.vue';
	export default {
		components: {
			xweek,
		},
		data() {
			return {
				//
				checkbox: [{
					value: 'A',
					checked: true
				}, {
					value: 'B',
					checked: true
				}, {
					value: 'C',
					checked: false
				}],
				// 滑动按钮
				 options:[
				  {
					name:'删除',
					width:100,
					background:'red',
					color:'#fff'
				  }
				],
				
				// 文字删除线
				isStrikethrough: false,
				
				// 悬浮框
				horizontal: 'right',
				vertical: 'bottom',
				direction: 'horizontal',
				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor:"#007AFF"
				},
				// 今天时间
				nowDate:'',
				nowTime: '',
				taskList:{
					mostHight: null,
					Hight: null,
					common: null,
					low: null,
				},
				areaShow:false,
				updateShow:false,
				areaTxt: undefined,
				modalName: null,
				task:{},
				staff:{},
				delayTask:{},
			}
		},
		onLoad(options){
			// this.staff = {
			// 	id: "42",
			// 	name:"孙恒",
			// 	userId: "SunHeng"
			// }
			// uni.setStorageSync('staff', this.staff);
			// var userId = options.userId;
			// console.log(userId)
			// if(userId){
			// }
			const currentDate = new Date();
			this.nowTime = this.formatDate(currentDate);
			this.nowDate = this.formatDate(currentDate);
			// if(!document.URL.split("=")[1]){
				this.staff = uni.getStorageSync("staff");
			// 	this.getTaskByIdAndTime();
			// 	this.getDelayTask();
			// } else {
			// 	this.code = document.URL.split("=")[1].split("&")[0];
			// 	this.toApp(this.code);
			// }
		},
		onShow(){
			// const currentDate = new Date();
			// const date2Obj  = new Date('2023-08-25');
			// this.nowTime = this.formatDate(currentDate);
			// this.nowDate = this.formatDate(currentDate);
			this.getTaskByIdAndTime();
			this.getDelayTask();
			uni.removeStorageSync("ids");
			uni.removeStorageSync("leader");
		},
		methods: {
			// 接收任务
			sureTask(c){
				let _this = this;
				request({
					url: common.api_base_url+'/task/updatSureState/' + c.id,
					data:{
					},
					header:{
					},
					method: 'GET',
					success: res => {
						
						_this.getTaskByIdAndTime();
					},
					fail: function(e) {
						uni.showToast({
							title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
							icon:"loading"
						})
					},
				});
			},
			// cs 测试跨页调用
			handleFilterType(param1, param2) {
			      // 处理过滤操作  
			      // 在这里调用<xweek>插件内部提供的过滤方法  
			      // ...  
				  console.log(222)
				  console.log(param1)
				  console.log(param2)
				  
			    },  
			    changeBack(data) {  
			      // 处理返回操作  
			      // ...  
				  console.log(333)
				  console.log(data)
			    },
			// 获取授权
			toApp(code){
				var _this = this;
				uni.request({
					url: common.api_base_url+'/app' ,
					data:{
						"code": code
					},
					header:{
					},
					method: 'GET',
					success: res => {
						_this.staff = res.data;
						uni.setStorageSync('staff', _this.staff);
						_this.getTaskByIdAndTime();
						_this.getDelayTask();
					},
					fail: function(e) {
						uni.showToast({
							title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
							icon:"loading"
						})
					},
				});
				_this.code = '';
			},
			// 滑动按钮 删除任务
			clickItem(c){
				let _this = this;
				uni.showModal({
				    title: '删除任务',
				    content: '您确定要删除这条任务吗',
				    success: function (res) {
				        if (res.confirm) {
							request({
								url: common.api_base_url+'/task/' + c.id,
								data:{
								},
								header:{
								},
								method: 'DELETE',
								success: res => {
									uni.showToast({
										title:"删除成功",
										duration: 1000,
									});
									_this.getTaskByIdAndTime();
								},
								fail: function(e) {
									uni.showToast({
										title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
										icon:"loading"
									})
								},
							});
				        } else if (res.cancel) {
				           res.cancel = true;
				        }
				    }
				});
			},
			// 悬浮框方法
			content(){},
			// 任务完成勾选框
			completeTask(task){
				task.states = !task.states;
				var _this = this;
				uni.request({
					url: common.api_base_url+'/task/changeStates',
					data:{
						"task": task
					},
					header:{
					},
					method: 'PUT',
					success: res => {
						if(res.data.success){
							_this.getTaskByIdAndTime();
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 2000,
								icon:"error"
							})
						}
					},
					fail: function(e) {
						uni.showToast({
							title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
							icon:"loading"
						})
					},
				});
			},
			// 悬浮框点击事件
			fabClick(){
				uni.navigateTo({
					url: `/pages/addTask/addTask`
				})
			},
			// 获取单个人员任务数据
			getTaskByIdAndTime(){
				this.taskList = [];
				this.task.staffId = this.staff.id;
				this.task.startTime = this.nowTime;
				var _this = this;
				uni.request({
					url: common.api_base_url+'/task/getStaffTask' ,
					data:{
						"task": _this.task
					},
					header:{
					},
					method: 'POST',
					success: res => {
						_this.taskList = res.data;
					},
					fail: function(e) {
						uni.showToast({
							title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
							icon:"loading"
						})
					},
				});
			},
			// 获取单个人员 延期任务 
			getDelayTask(){
				this.delayTask = [];
				this.task.staffId = this.staff.id;
				this.task.startTime = this.nowTime;
				var _this = this;
				uni.request({
					url: common.api_base_url+'/task/selectDelayTask' ,
					data:{
						"task": _this.task
					},
					header:{
					},
					method: 'POST',
					success: res => {
						// 假装本人数据
						_this.delayTask = res.data;
						console.log(res.data)
					},
					fail: function(e) {
						uni.showToast({
							title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
							icon:"loading"
						})
					},
				});
			},
			
			// 周日期控件
			 changeBack:function(d){
				 this.nowTime = d;
				 this.getTaskByIdAndTime();
			},
			// 获取任务列表
			getTaskList(){
				var _this = this;
				uni.request({
					url: common.api_base_url+'/task',
					data:{
					},
					header:{
					},
					method: 'GET',
					success: res => {
 						_this.taskList = res.data;
					},
					fail: function(e) {
						uni.showToast({
							title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
							icon:"loading"
						})
					},
				});
			},
			// 评论弹窗取消
			cancelAdd(){
				this.areaShow = false;
				this.updateShow = false;
				this.areaTxt='';
			},
			// 评论弹窗确定
			confirmAdd(){
				this.areaShow = false;
				var _this = this;
				uni.request({
					url: common.api_base_url+'/comment',
					data:{
						"taskId":_this.task.id,
						"staffId":_this.task.staffId,
						"content":_this.areaTxt,
						// "leadId": _this.startDate,
					},
					header:{
					},
					method: 'PUT',
					success: res => {
						uni.showToast({
							title:"删除成功",
							duration: 1000
						})
						_this.getTaskList();
					},
					fail: function(e) {
						uni.showToast({
							title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
							icon:"loading"
						})
					},
				});
				this.areaTxt='';
			},
			// 显示评论弹窗
			addComment(task){
				this.task = task;
				this.areaShow = true;
			},
			// 评论输入框
			textareaAInput(e) {
				this.areaTxt = e.detail.value
			},
			// 删除评论
			delComment(e){
				let _this = this;
				uni.showModal({
				    title: '删除任务',
				    content: '您确定要删除这条评论吗？',
				    success: function (res) {
				        if (res.confirm) {
							uni.request({
								url: common.api_base_url+'/comment/' + e.id,
								data:{
								},
								header:{
								},
								method: 'DELETE',
								success: res => {
									uni.showToast({
										title:"删除成功",
										duration: 1000,
									});
									_this.getTaskList();
								},
								fail: function(e) {
									uni.showToast({
										title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
										icon:"loading"
									})
								},
							});
				        } else if (res.cancel) {
							res.cancel = true;
				        }
				    }
				});
			},
			// 修改进度弹出框
			updateTask(task){
				this.task = task;
				this.updateShow = true;
			},
			// 提交修改进度
			updateProcess(){
				this.task.taskProgress = this.areaTxt;
				var _this = this;
				uni.request({
					url: common.api_base_url+'/task',
					data:{
						"task": _this.task,
					},
					header:{
					},
					method: 'PUT',
					success: res => {
						if(res.data.success){
							uni.showToast({
								title:"修改成功",
								duration: 1000
							})
						} else {
							uni.showToast({
								title: "输入进程有误",
								duration: 2000,
								icon:"error"
							})
						}
						_this.getTaskList();
					},
					fail: function(e) {
						uni.showToast({
							title:"唉哟，程序错误了["+JSON.stringify(e)+"]",
							icon:"loading"
						})
					},
				});
				this.updateShow = false;
				this.areaTxt = '';
			},
			// 页面跳转
			getTaskDetail(task){
				this.task = task;
				uni.navigateTo({
					url: `/pages/showList/taskDetail?id=${this.task.id}`
				})
				// uni.navigateTo({
				// 	url:'/pages/showList/taskDetail?task='+ encodeURIComponent(JSON.stringify(this.task)),
				// })
			},
			// 时间转换格式方法
			formatDate(date) {
			  const year = date.getFullYear();
			  const month = String(date.getMonth() + 1).padStart(2, '0');
			  const day = String(date.getDate()).padStart(2, '0');
			  return `${year}-${month}-${day}`;
			},
			// 计算两个时间差值
			calculateDifference(endTime, nowDate) {
				  
				var endTime = new Date(endTime);
				var nowDate = new Date(nowDate);  
				
				if(nowDate <= endTime){
					roundedDiffDays = -1;
				} else{
					// 计算日期差值（以天为单位）  
					var diffDays = Math.abs(nowDate - endTime) / (1000 * 3600 * 24);  
					// 使用Math.ceil()函数向上取整
					var roundedDiffDays = Math.ceil(diffDays); 
				}
				// 返回时间差值
				return roundedDiffDays;
			}
		},
		created() {
		    // 在组件创建时，为 nowTime 设置当前日期
		   
		}
	}
</script>

<style scoped>
	.strikethrough {
	  text-decoration: line-through;
	  color: #666;
	}
	
.container {
	width: 100%;
  display: flex;
  align-items: center;
}

/* cs */ 

</style>




